//配置axios
// 导入
import axios from 'axios';
import qs from 'qs';
// axios.defaults.baseURL = 'http://47.93.206.13:5588';
axios.defaults.baseURL = 'http://101.132.252.174:8001';
const token =
  'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJOZz09Iiwic3ViIjoiYWRtaW4xIiwiaXNzIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJpYXQiOjE2MTAyNDE3MjEsImF1ZCI6InJlc3RhcGl1c2VyIiwiZXhwIjoxNjEwNDE0NTIxLCJuYmYiOjE2MTAyNDE3MjF9.o0PMAZt5EzsLjyriYwHwrUDuX9wJJXzgdCV-PzN6JRc';
// 请求拦截器
axios.interceptors.request.use(config => {  
  // Do something before request is sent
  // console.log(config, '-----');
  // alert(1);

  config.headers = {
    //accept:'',
    ...config.headers,
    Authorization: sessionStorage.getItem('token')
  }
  if (config.method == 'post' && config.url !== "/user/login") {
    config.data = qs.stringify(config.data);
  }
  return config;
}, error => {
  // Do something with request error
  return Promise.reject(error);
});
// 响应拦截器
axios.interceptors.response.use(response => {
  // Do something before response is sent
  // console.log(response, '++++');
  let res = {
    ...response,
    data: response.data.data,
    status: response.data.status,
    statusText: response.data.message,
    timestamp: response.data.timestamp
  }
  return res;
}, error => {
  // Do something with response error
  return Promise.reject(error);
});




// 导出
export default axios;